package com.freework.report.util;

import jxl.format.RGB;

public class ColorUtil {

	final static String BLACK="#000000";
	final static String WHITE="#ffffff";
	
	public static String toHexString(int []rgb){
		
		if(rgb==null||rgb.length<3)
		 return WHITE;
		return  toHexString(rgb[0],rgb[1],rgb[2]);
	}
	
	public static String toHexString(int r,int g,int b){
		if(r==0&&g==0&&b==0)
			return WHITE;
		if(r==255&&g==255&&b==255)
			return BLACK;
		int rgb = ((255 & 0xFF) << 24) |
        ((r & 0xFF) << 16) |
        ((g & 0xFF) << 8)  |
        ((b & 0xFF) << 0);
		String hex=Integer.toHexString(rgb & 0x00ffffff );
		if(hex.length()==6)
			return "#"+hex;
		
		return BLACK.substring(0, 7-hex.length())+hex;
		
		
	
	}
	

	public static void main(String args[]){
		
		for (int i = 1; i <255; i+=10) {
			System.out.println("<TD style=\"color: "+toHexString(new int[]{i,i*5,i*3})+";\"><strong>aaaaa</strong></TD>");
		}
	}
	
	
	
	public  static int[] getRGBIntArray(jxl.format.Colour Colour){
		RGB rgb=Colour.getDefaultRGB();
		return new int[]{  rgb.getRed(),rgb.getGreen(),rgb.getBlue()};
	}
}
